package easy;

public class Solution_1588 {

    public int sumOddLengthSubarrays(int[] arr) {
        int[] sums = new int[arr.length];
        sums[0] = arr[0];
        for (int i = 1; i < arr.length; i++) {
            sums[i] = arr[i] + sums[i - 1];
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j >= 0; j -= 2) {
                int temp = sums[i] - (j == 0 ? 0 : sums[j - 1]);
                sum += temp;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        Solution_1588 model = new Solution_1588();
        System.out.println(model.sumOddLengthSubarrays(new int[]{1, 4, 2, 5, 3}));
        System.out.println(model.sumOddLengthSubarrays(new int[]{3}));
    }
}
